Component({
  data: {
    note: [],
  },
  attached() {
    this.getdata()
  },
  pageLifetimes: {
    show: function () {
      this.getdata()
    }
  },
  methods: {
    // 获取一个图片
    imgsitem: function (resdata) {
      let arr = []
      for (let i = 0; i < resdata.length; i++) {
        let img = JSON.parse(resdata[i].img_url)[0]
        resdata[i].img_url = img
        arr = resdata
      }
      return arr
    },
    // 获取数据的函数
    getdata: function () {
      let that = this
      wx.$request('foodfriends/releasedata', 'post', ).then(res => {
        let resdata = res.data.data
        if (res.statusCode === 200 && res.data.code == 200) {
          let data = that.imgsitem(resdata)

          that.setData({
            note: data
          })
        }
      }).catch(err => {
        wx.showToast({
          title: '获取失败',
        })
      })
    },

    // 跳转到发布页面
    goRelease: function () {
      wx.navigateTo({
        url: '/pages/foodfriends/release/release',
      })
    },
    // 跳转到详情页
    goDetails: function (e) {
      let id = e.currentTarget.dataset.id
      wx.navigateTo({
        url: `/pages/foodfriends/releaseDetails/releaseDetails?id=${id}`
      })
    },
    // 点赞
    addFabu: function (e) {
      let id = e.currentTarget.dataset.release_id
      // 调用app中的方法
      wx.$addFabulous(id)
      setTimeout(() => {
        this.getdata()
      }, 1000)
    },
  },
})